<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>

<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list" >
                    <ul>
                        <li>
                            年级名:
                            <select name="gradeId" style="width: 170px">
                                <option>请选择</option>
                                <c:forEach items="${grades}" var="grade">
                                    <option value="${grade.id}">${grade.name}</option>
                                </c:forEach>
                            </select>
                        </li>
                        <li>
                            课程名:
                            <select name="courseId" style="width: 170px" disabled>
                                <option>请选择</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

<%--        <div class="btn-group-sm" id="toolbar" role="group">--%>
<%--            <a class="btn btn-success" onclick="$.operate.add()">--%>
<%--                <i class="fa fa-plus"></i> 新增--%>
<%--            </a>--%>
<%--            &lt;%&ndash;<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()">--%>
<%--                <i class="fa fa-edit"></i> 修改--%>
<%--            </a>&ndash;%&gt;--%>
<%--            <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">--%>
<%--                <i class="fa fa-remove"></i> 批量删除--%>
<%--            </a>--%>
<%--        </div>--%>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<%@include file="../../common/include-footer.jsp" %>
<script th:inline="javascript">
    var prefix = "/course";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/update/{id}",
            removeUrl: prefix ,
            sortName: "",
            // rememberSelected: true,
            height: 500,
            modalName: "课程",
            columns: [
                {
                    field: 'id',
                    title: '章节编号'
                },
                {
                    field: 'name',
                    title: '章节名称'
                },
                // {
                //     title: '操作',
                //     align: 'center',
                //     formatter: function (value, row, index) {
                //         var actions = [];
                //         actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="$.operate.edit(\'' + row.subid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="$.operate.remove(\'' + row.subid + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
                ]
        };
        $.table.init(options);

        $('select[name=gradeId]').change(function () {
            var gradeId = $(this).val();
            $.ajax({
                url:"${pageContext.request.contextPath}/course/getCourseByGradeId",    //请求的url地址
                dataType:"json",   //返回格式为json
                data:{"gradeId":gradeId},    //参数值
                type:"POST",   //请求方式
                success:function(data){
                    $('.examC').remove();
                    var courses = data;
                    for(var i=0;i<courses.length;i++){
                        var id = courses[i].id;
                        var name =courses[i].name;
                        // $("#subid").val([subid,subname]);
                        //给下拉框动态赋值
                        $("select[name=courseId]").append("<option value='"+id+"' class='examC'>"+name+"</option>");
                    }
                    // alert($("#subid").val());
                }

            });
            $('select[name=courseId]').attr("disabled",false);
        });
    });
</script>
</body>
</html>
